import React, { Component } from 'react'
import PropTypes from 'prop-types'

export default class User extends Component {
    static propTypes = {
        username: PropTypes.string,
        age : PropTypes.number,
        work: PropTypes.string.isRequired
    }
    static defaultProps = {
        work:'富婆'  //不传的就是默认值
    }
    render() {
        const {userName, age, work} = this.props;
        return (
            <div>
                <ul>
                    <li>姓名：{userName}</li>
                    <li>年龄：{age}</li>
                    <li>工作：{work}</li>
                </ul>
            </div>
        )
    }
}
//与上面二选一，最好是上面那个，在同一个组件里
// User.propTypes = {
//     username: PropTypes.string,
//     age : PropTypes.number,
//     work: PropTypes.string.isRequired  //表示必填
// }
